home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Tumbler and Podium / Tumbler_utility.c < prev    next >
Encoding:
Text File  |  1995-05-31  |  2.2 KB  |  81 lines  |  [TEXT/MPS ]

  1. //
  2. //
  3. //        utility.c
  4. //
  5. //        Utility routines.
  6. //        
  7. //
  8. //        Author:        Nick Thompson & Pablo Fernicola, with thanks to the QuickDraw 3D team
  9. //
  10. //        Copyright © 1992-95 Apple Computer, Inc., All Rights Reserved
  11. //
  12. //
  13.  
  14.  
  15. #include "Tumbler_prototypes.h"
  16.  
  17. #include "Tumbler_utility.h"
  18. //
  19. //    PStrCmp returns true if the two given pascal strings are equal.
  20. //
  21.  
  22. short PStrCmp(char *s1, char *s2)
  23.  
  24. {    short        size, index;
  25.  
  26.     size = s1[0] + 1;
  27.  
  28.     while (size--) {
  29.         if (*(s1++) != *(s2++))
  30.             return(false);
  31.     }
  32.  
  33.     return(true);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. //--------------------------------------------------------------------------------
  40. // Given two rects, this function centers the second one within the first. 
  41.  
  42. void    CenterRectInRect(Rect *outerRect, Rect *innerRect)
  43. {
  44.     PositionRectInRect(outerRect, innerRect, FixRatio(1, 2), FixRatio(1, 2));
  45. }
  46.  
  47. //-------------------------------------------------------------------------------------------
  48. // Given two rectangles, this function positions the second within the first
  49. // one so that it maintains the spacing specified by the horzRatio and
  50. // vertRatio parameters.  In other words, to center an inner rectangle
  51. // hoizontally, but have its center be 1/3 from the top of the outer rectangle,
  52. // call this function with horzRatio = FixRatio(1, 2), vertRatio =
  53. // FixRatio(1, 3).  We use Fixed rather than floating point to avoid
  54. // complications when mixing MC68881/non-MC68881 versions of Utilities. 
  55.  
  56. void    PositionRectInRect(Rect *outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio)
  57. {
  58.     short    outerRectHeight;
  59.     short    outerRectWidth;
  60.     short    innerRectHeight;
  61.     short    innerRectWidth;
  62.     short    yLocation;
  63.     short    xLocation;
  64.  
  65.     outerRectHeight = outerRect->bottom - outerRect->top;
  66.     outerRectWidth = outerRect->right - outerRect->left;
  67.  
  68.     innerRectHeight = innerRect->bottom - innerRect->top;
  69.     innerRectWidth = innerRect->right - innerRect->left;
  70.         yLocation = Fix2Long(FixMul(Long2Fix(outerRectHeight - innerRectHeight), vertRatio))
  71.             + outerRect->top;
  72.         xLocation = Fix2Long(FixMul(Long2Fix(outerRectWidth - innerRectWidth), horzRatio))
  73.             + outerRect->left;
  74.  
  75.     innerRect->top = yLocation;
  76.     innerRect->left = xLocation;
  77.     innerRect->bottom = yLocation + innerRectHeight;
  78.     innerRect->right = xLocation + innerRectWidth;
  79. }
  80.  
  81.